import type {RouteRecordRaw} from "vue-router";

// 定义模块类型
interface RouteModuleType {
    default: RouteRecordRaw[]
}

/**
 * 合并动态路由模块的默认导出
 * @param routeModules 动态导入的路由模块对象
 * @returns 合并后的路由配置数组
 */
const mergeRouteModules = (routeModules: Record<string, unknown>): RouteRecordRaw[] => {
    const mergeRoutes: RouteRecordRaw[] = [];
    const routeModulesVal = Object.values(routeModules)

    for (const routeModule of routeModulesVal) {
        const moduleRoutes = (routeModule as RouteModuleType)?.default ?? [];
        mergeRoutes.push(...moduleRoutes)
    }
    return mergeRoutes;
}

export { mergeRouteModules };
export type { RouteModuleType };